<admintpl file="header" />
</head>
<body>
	<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=ae2231ad4a1e87e1b4701c5fbc67eac9"></script>
    <style>
    	body,html,#mapContainer{
    		width: 100%;
    		height: 100%;
    		font-family: "微软雅黑";
    	}
    </style>
    <div class="wrap js-check-wrap" style="padding-bottom: 0;">
        <ul class="nav nav-tabs">
            <li><a href="{:U('Store/index')}">店铺列表</a></li>
            <li class="active"><a>修改店铺</a></li>
        </ul>
        <form action="{:U('Store/edit_post')}" method="post" class="form-horizontal js-ajax-form" enctype="multipart/form-data">
            <div class="row-fluid">
                <div class="span7">
                    <table class="table table-bordered">
                        <tr>
                            <th>店铺名称</th>
                            <td>
                            	<input type="hidden" name="sid" value="{$store.id}" />
                                <input type="text" name="title" value="{$store.title}"/>
                            </td>
                            <th>子名称</th>
                            <td><input type="text" name="title_branch" value="{$store.title_branch}"/></td>
                        </tr>
                        <tr>
                            <th>店铺地址</th>
                            <td><input type="text" name="address" value="{$store.address}"/></td>
                            <th>店铺类型</th>
                            <td>
                                <select name="stype">
                                    <foreach name="stype" item="vo">
                                        <option value="{$vo.id}"<if condition="$vo['id'] eq $store['stype']" >selected </if>>{$vo.name}</option>
                                    </foreach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th>创建日期</th>
                            <td><input type="text" readonly="readonly" value="{$store.add_time}"/></td>
                            <th>更新日期</th>
                            <td><input type="text" readonly="readonly" value="{$store.update_time}"/></td>
                        </tr>
                        <tr>
                            <th>设备坐标(经)</th>
                            <td><input type="text" readonly="readonly" value="{$store.longitude}"/></td>
                            <th>设备坐标(纬)</th>
                            <td><input type="text" readonly="readonly" value="{$store.latitude}"/></td>
                        </tr>
                    	<tr>
                            <th>分店店长</th>
                            <td>
                            <foreach name="susers" item="vo">
								<if condition="$vo['oid'] eq $store['user_id']">
									{$vo.realname} - {$vo.mobile}
								</if>
                            </foreach>
                            </td>
                            <th>总店店长</th>
                            <td>
                            <foreach name="susers" item="vo">
								<if condition="$vo['oid'] eq $store['owner_id']">
									{$vo.realname} - {$vo.mobile}
								</if>
                            </foreach>
                        </tr>
                    	<tr>
                            </td>
                            <th>市场人员</th>
                            <td>
                            <foreach name="susers" item="vo">
								<if condition="$vo['oid'] eq $store['marketing_id']">
									{$vo.realname} - {$vo.mobile}
								</if>
                            </foreach>
                            </td>
                            <th>经销商</th>
                            <td>
                            <foreach name="susers" item="vo">
								<if condition="$vo['oid'] eq $store['agency_id']">
									{$vo.realname} - {$vo.mobile}
								</if>
                            </foreach>
                            </td>
                       </tr>
                    	<tr>
                            <th>签约人员</th>
                            <td>
                            <foreach name="susers" item="vo">
								<if condition="$vo['oid'] eq $store['sign_user_id']">
									{$vo.realname} - {$vo.mobile}
								</if>
                            </foreach>
                            </td>
                            <th>省 - 市 - 区</th>
                            <td>
                            <foreach name="region" item="vo">
								<if condition="$vo['code'] eq $store['province_id']">
									{$vo.name}
								</if>
                            </foreach>
                            -
                            <foreach name="region" item="vo">
								<if condition="$vo['code'] eq $store['city_id']">
									{$vo.name}
								</if>
                            </foreach>
                            -
                            <foreach name="region" item="vo">
								<if condition="$vo['code'] eq $store['district_id']">
									{$vo.name}
								</if>
                            </foreach>
                            </td>
                       </tr>
                    </table>
                </div>
    		<div class="span5">
				<table width="100%"  cellpadding="2" cellspacing="2" class="table table-bordered">
						<tr><td><b>地图信息</b></td></tr>
						<tr><td style="height:265px;"><div id="mapContainer"></div></td></tr>
				</table>
			</div>
            </div>
            <div class="form-actions" style="margin-top:0">
                <button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
                <a class="btn" href="{:U('Store/index')}">返回</a>
            </div>
        </form>
    </div>
    <div class="wrap js-check-wrap" <if condition="!$devices" >style="display: none;"</if>>
        <form action="{:U('Store/loding_post')}" method="post" class="form-horizontal js-ajax-form" enctype="multipart/form-data">
    	<div class="row-fluid">
	        <div class="span7">
		        <table class="table table-hover table-bordered">
		            <thead>
		                <tr>
		                    <th width="20"></th>
		                    <th>设备ID/条形码</th>
		                    <th>major/minor</th>
		                    <th>设备类型/设备状态</th>
		                    <th width="40">Loding</th>
		                    <th width="70">操作</th>
		                </tr>
		            </thead>
		            <foreach name="devices" item="vo">
		                <tr>
		                	<td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="devid[]" value="{$vo.id}" title="ID:{$vo.id}"></td>
		                    <td>{$vo.devid}<br>{$vo.barcode}</td>
		                    <td>{$vo.major}<br>{$vo.minor}</td>
		                    <td>{$vo.remark}<br>{$bstatus[$vo['status']]['name']}</td>
		                    <td style="padding: 0;margin: 0;"><if condition="$vo['loding']"><img src="{$urlimg}{$vo.loding}"></if></td>
		                    <td>
		                    	<if condition="$vo['loding']">
								<a href="{:U('Store/remove_loding', array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="你确定移除Loding图吗？">移除Loding</a>
								</if><br>
								<a href="{:U('Device/edit', array('id'=>$vo['id']))}">{:L('EDIT')}</a> |
								<a href="{:U('Store/remove', array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="解绑后不可恢复，你确定吗？">解绑</a>
							</td>
		                </tr>
		            </foreach>
		        </table>
	        </div>
	        <div class="span5">
				<table class="table table-bordered">
					<td><b>Loding</b></td>
					<tr><td>
						<input type="file" readonly="readonly" name="loding_img" id="adfile" accept="image/*"/>
						<input type="button" class="btn btn-small" onclick="$('#adfile').attr('value','');$('#aimg').attr('src','');return false;" value="取消图片">
					</td></tr>
					<tr><td><img src="" id="aimg"></td></tr>
				</table>
	        </div>
   		</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('Store/index')}">返回</a>
			</div>
    	</form>
    </div>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
	$("#adfile").change(function(){
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$("#aimg").attr("src", objUrl) ;
		}
	}) ;
	function getObjectURL(file) {
		var url = null ;
		if (window.createObjectURL!=undefined) { // basic
			url = window.createObjectURL(file) ;
		} else if (window.URL!=undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file) ;
		} else if (window.webkitURL!=undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file) ;
		}
		return url ;
	}
    var infoWindow;
    //初始化地图对象，加载地图
    var map = new AMap.Map("mapContainer", {
        resizeEnable: true,
        zoom: 15,
        center:[{$store.longitude},{$store.latitude}]
    });
    addMarker();
    //添加marker标记
    function addMarker() {
        map.clearMap();
        var marker = new AMap.Marker({
            map: map,
            //位置
            position: [{$store.longitude},{$store.latitude}]
        });
        //鼠标点击marker弹出自定义的信息窗体
        AMap.event.addListener(marker, 'click', function() {
            infoWindow.open(map, marker.getPosition());
        });
    }
    //在指定位置打开信息窗体
    function openInfo() {
        //构建信息窗体中显示的内容
        var info = [];
        info.push("<div style=\"padding:0px 0px 0px 4px;\"><b>{$store.title}({$store.title_branch})</b>");
        info.push("地址 : {$store.address}</div>");

        infoWindow = new AMap.InfoWindow({
            content: info.join("<br/>"),  //使用默认信息窗体框样式，显示信息内容
        	offset: new AMap.Pixel(0, -15)//-113, -140
        });
        infoWindow.open(map, [{$store.longitude},{$store.latitude}]);
    }
    openInfo();


	</script>
</body>
</html>
